﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using ScreenSaver.Properties;

namespace ScreenSaver
{
    public partial class SetScreenSaver : Form
    {
       Microsoft.DirectX.DirectInput.Key keyEnd;
        public SetScreenSaver()
        {
            InitializeComponent();
        }

        private void KeyEnabled_KeyDown(object sender, KeyEventArgs e)
        {
            keyEnd = (Microsoft.DirectX.DirectInput.Key)e.KeyCode;
            KeyDisabled.Text = e.KeyCode.ToString();
        }

        private void SetScreenSaver_Load(object sender, EventArgs e)
        {
            chkMouseEnd.Checked = Settings.Default.MouseEnd;
            KeyDisabled.Text = Settings.Default.KeyEnd.ToString();
            KeyEnabled.Text = Settings.Default.KeyEnd.ToString();
            chkSoundtrack.Checked = Settings.Default.SoundtrackOn;
            if (chkSoundtrack.Checked)
            {
                txtbChooseMusicFile.Text = Settings.Default.Soundtrack;
                btnChooseMusicFile.Enabled = true;
            }
            chkSoundEffects.Checked = Settings.Default.SoundEffectsOn;
        }

        private void chkMouseEnd_CheckedChanged(object sender, EventArgs e)
        {
            //Settings.Default.MouseEnd = true;
        }

        private void KeyEnabled_TextChanged(object sender, EventArgs e)
        {

        }

        private void chkSoundEffects_CheckedChanged(object sender, EventArgs e)
        {
            //Settings.Default.SoundEffectsOn = chkSoundEffects.Checked;
        }

        private void chkSoundtrack_CheckedChanged(object sender, EventArgs e)
        {
            if (chkSoundtrack.Checked)
            {
                btnChooseMusicFile.Enabled = true;
            }
        }

        private void btnChooseMusicFile_Click(object sender, EventArgs e)
        {
            ChooseMusicFile.CheckFileExists = true;
            ChooseMusicFile.Filter = "Pliki dźwiękowe|*.wav;*.mp3";
            ChooseMusicFile.Multiselect = false;
            if (ChooseMusicFile.ShowDialog() == DialogResult.OK)
            {
                //Settings.Default.Soundtrack = ChooseMusicFile.FileName;
                //Settings.Default.SoundtrackOn = true;
                txtbChooseMusicFile.Text = ChooseMusicFile.FileName;
            }
        }

        private void btnSave_Click(object sender, EventArgs e)
        {
            Settings.Default.MouseEnd = chkMouseEnd.Checked;
            Settings.Default.KeyEnd = keyEnd;
            Settings.Default.SoundtrackOn = chkSoundtrack.Checked;
            if (chkSoundtrack.Checked)
            {
                if (File.Exists(txtbChooseMusicFile.Text))
                {
                    Settings.Default.Soundtrack = txtbChooseMusicFile.Text;
                    Settings.Default.SoundtrackOn = true;
                }
            }
            Settings.Default.SoundEffectsOn = chkSoundEffects.Checked;
            Settings.Default.Save();
            this.Close();
        }
    }
}
